const options = [
  {
    values: [
      { label: 'b2c', value: 'b2c' },
      { label: 'bco', value: 'bco' },
      { label: 'o2o', value: 'o2o' },
      { label: 'b2c1', value: 'b2c1' },
      { label: 'bco1', value: 'bco1' },
      { label: 'o2o1', value: 'o2o1' },
    ],
  },
  {
    values: [
      { label: '3d10d0', value: '3d10d0' },
      { label: 'demo3.0', value: 'demo3.0' },
      { label: 'upgrade3.0', value: 'upgrade3.0' },
      { label: 'yuanyang', value: 'yuanyang' },
      { label: 'demo30', value: 'demo30' },
      { label: 'changan', value: 'changan' },
      { label: 'panku', value: 'panku' },
      { label: 'jiaofu', value: 'jiaofu' },
    ],
  },
  {
    values: [
      { label: 'dev', value: 'dev' },
      { label: 'trunk', value: 'trunk' },
      { label: 'stg', value: 'stg' },
      { label: 'prod', value: 'prod' },
    ],
  },
]

const urlMap = {}
const [{ values: platformValues }, { values: domainValues }, { values: envValues }] = options
const templateMap = {
  '3d10d0': 'http://m${platform}-${domain}.${env}.oudianyun.com',
  'demo3.0': 'http://m${platform}.${domain}-${env}.oudianyun.com',
  'upgrade3.0': 'http://m${platform}.${domain}-${env}.oudianyun.com',
  // yuanyang: 'http://m${platform}.${domain}-${env}.oudianyun.com',
  demo30: 'https://m${platform}-${domain}-${env}.oudianyun.com',
  changan: 'http://m${platform}-demo30-${env}-0516.oudianyun.com',
  jiaofu: 'http://m${platform}-jiaofu30-${env}.oudianyun.com/',
  longguang: 'https://mallbco.logan.com.cn',
  panku: 'https://h5.pandadiscovery.cn',
  yuanyang: 'https://mbco.yiyunzhihui.com',
}

const getUrl = (platform, domain, env) => {
  const template = templateMap[domain]
  const obj = { platform, domain, env }
  const url = template.replace(/\$\{(\w+)\}/g, ($0, $1) => obj[$1])

  return url
}

platformValues.forEach(({ value: platform }) => {
  domainValues.forEach(({ value: domain }) => {
    envValues.forEach(({ value: env }) => {
      const url = getUrl(platform, domain, env)

      urlMap[url] = [platform, domain, env]
    })
  })
})

// console.log('urlMap', urlMap)

module.exports = {
  options,
  urlMap,
  getUrl,
}
